import { memo, useState } from "react";
import Taro, { useLoad } from "@tarojs/taro";
import { View, Input, Textarea } from "@tarojs/components";
import request from "@/services/index.ts";
import styles from "./index.module.scss";

const formDate = [
  { prop: "linkName", lable: "昵称" },
  { prop: "linkCompony", lable: "公司" },
  { prop: "linkPhone", lable: "手机" },
];

const Index = memo(function () {
  const [from, setfrom] = useState({linkName:'',linkCompony:'',linkPhone:''})
  const [btnTitle, setbtnTitle] = useState("提交")

  function submit(){
    let obj={
      link:Taro.getStorageSync('link'),
      eid:Taro.getStorageSync('eid')
   }
  // if(!from.linkName)
    request.post("/link",{...obj,...from}).then((res) => {
      // setfrom({...from,...{linkName:'',linkCompony:'',linkPhone:''}})
      setbtnTitle("提交成功")
    });
  }
  const changde=(e,r)=>{
    from[r]=e.detail.value
  }
  return (
    <View className={`${styles.page} backgroundImg`}>
      <View className={`${styles.innerBox}`}>
        {formDate.map((item) => {
          return (
            <View key={item.prop} className={`${styles.itemed}`}>
              {" "}
              <View>{item.lable}:</View>
              <Input
                name={item.prop}
                onInput={(e)=>changde(e,item.prop)}
                className={`${styles.input}`}
                type="text"
                placeholder={`请输入${item.lable}`}
                focus
              />
            </View>
          );
        })}
        <View className={`${styles.itemed}`}>
          <View>补充:</View>
          <Textarea
            onInput={(e)=>changde(e,'linkDescribe')}
            className={`${styles.textare}`}
            placeholder="请输入补充"
            placeholder-style="color:red;"
          />
        </View>
        <View onClick={()=>{submit()}} className={`${styles.subBtn}`}>{btnTitle}</View>
      </View>
    </View>
  );
});

export default Index;
